package com.crossriver.crgis.cofo.util;

import java.util.List;

import com.crossriver.crgis.database.model.Application_C_of_O;
import com.crossriver.crgis.database.model.Company_Contact_Person;
import com.crossriver.crgis.database.model.Contact_Information;
import com.crossriver.crgis.database.model.Held_Plots;
import com.crossriver.crgis.database.model.Individual_Information;
import com.crossriver.crgis.database.model.Organisation_Information;
import com.crossriver.crgis.database.model.Property_Information;
import com.crossriver.crgis.database.model.impl.Held_PlotsImpl;
import com.crossriver.crgis.database.service.Held_PlotsLocalServiceUtil;
import com.liferay.portal.kernel.util.Validator;

public class ApplicationValidator {
public static boolean validateOldCofO(Application_C_of_O application, List<String> errors){
		
		boolean foundError = false;
		if (application.getOldCofONo() == null || application.getOldCofONo().equalsIgnoreCase("")){
			errors.add("old-cofo-mandatory");
			foundError = true;
		}
		if (application.getFileNo() == null || application.getFileNo().equalsIgnoreCase("")){
			errors.add("file-no-mandatory");
			foundError = true;
		}
		return foundError;
	}
public static boolean validateApplication_C_of_O(Application_C_of_O application, List<String> errors){
		
		boolean foundError = false;
		if (application.getApplicationType() == null || application.getApplicationType().equalsIgnoreCase("")){
			errors.add("application-type-mandatory");
			foundError = true;
		}
		
		return foundError;
	}
	
public static boolean validateAddress_Information(Contact_Information contactInfo, List<String> errors){
		
		boolean foundError = false;
		if (contactInfo.getHouseNo() == null || contactInfo.getHouseNo().equalsIgnoreCase("")){
			errors.add("house-no-mandatory");
			foundError = true;
		}
		if (contactInfo.getAddressLine1() == null || contactInfo.getAddressLine1().equalsIgnoreCase("")){
			errors.add("address-is-mandatory");
			foundError = true;
		}
		if (contactInfo.getCity() == null || contactInfo.getCity().equalsIgnoreCase("")){
			errors.add("city-is-mandatory");
			foundError = true;
		}
		if (contactInfo.getCountry() == null || contactInfo.getCountry().equalsIgnoreCase("")){
			errors.add("country-is-mandatory");
			foundError = true;
		}
		if (contactInfo.getState() == null || contactInfo.getState().equalsIgnoreCase("")){
			errors.add("state-is-mandatory");
			foundError = true;
		}

		return foundError;
	}
	
	public static boolean validateIndividual_Information(Individual_Information indInformation, List<String> errors){
		boolean foundError = false;
		if (indInformation.getTitle() == null || indInformation.getTitle().equalsIgnoreCase("")){
			errors.add("title-is-mandatory");
			foundError = true;
		}
		
		if (indInformation.getLastName() == null || indInformation.getLastName().equalsIgnoreCase("")){
			errors.add("last-name-is-mandatory");
			foundError = true;
		}
		if (indInformation.getFirstName() == null || indInformation.getFirstName().equalsIgnoreCase("")){
			errors.add("first-name-is-mandatory");
			foundError = true;
		}
		if (indInformation.getOccupation() == null || indInformation.getOccupation().equalsIgnoreCase("")){
			errors.add("occupation-is-mandatory");
			foundError = true;
		}
		if (indInformation.getGender() == null || indInformation.getGender().equalsIgnoreCase("")){
			errors.add("gender-is-mandatory");
			foundError = true;
		}
		if (indInformation.getIdentificationDoc() == null || indInformation.getIdentificationDoc().equalsIgnoreCase("")){
			errors.add("identification-is-mandatory");
			foundError = true;
		}
		if (indInformation.getIdentificationDocNo() == null || indInformation.getIdentificationDocNo().equalsIgnoreCase("")){
			errors.add("identification_number-is-mandatory");
			foundError = true;
		}
		return foundError;
	}

	
	public static boolean validateOrganisation_Information(Organisation_Information indInformation, List<String> errors){
		boolean foundError = false;
		if (indInformation.getOrganisationName() == null || indInformation.getOrganisationName().equalsIgnoreCase("")){
			errors.add("organization-name-is-mandatory");
			foundError = true;
		}
		if (indInformation.getRegNo() == null || indInformation.getRegNo().equalsIgnoreCase("")){
			errors.add("rc-no-is-mandatory");
			foundError = true;
		}
		if (indInformation.getCountryOfReg() == null || indInformation.getCountryOfReg().equalsIgnoreCase("")){
		errors.add("country-of-reg-is-mandatory");
		foundError = true;
	}
	
	if (indInformation.getDateOfRegistration() == null ){
		errors.add("dateofregistration-is-mandatory");
		foundError = true;
	}
		
		return foundError;
	}

	public static boolean validateAttestation(Application_C_of_O application, List<String> errors){
		
		boolean foundError = false;
		if (!"false".equalsIgnoreCase(application.getAttestation())){
			foundError = false;
		}else{
			errors.add("you-must-check-attestation-to-procced");
			foundError = true;
		}
		return foundError;
	}

	public static boolean validateCompany_Contact_Person(
			Company_Contact_Person coyContPerson, List<String> errors) {
boolean foundError = false;
			if (coyContPerson.getDesignation() == null || coyContPerson.getDesignation().equalsIgnoreCase("")){
					errors.add("designation-is-mandatory");
					foundError = true;
				}
		if (coyContPerson.getPhoneMobile() == null || coyContPerson.getPhoneMobile().equalsIgnoreCase("")){
			errors.add("mobile-no-mandatory");
			foundError = true;
		}
		if (coyContPerson.getEmailAddress() == null || coyContPerson.getEmailAddress().equalsIgnoreCase("")){
			errors.add("email-is-mandatory");
			foundError = true;
		}
		if (coyContPerson.getFirstName() == null || coyContPerson.getFirstName().equalsIgnoreCase("")){
			errors.add("first-name-is-mandatory");
			foundError = true;
		}
		if (coyContPerson.getLastName() == null || coyContPerson.getLastName().equalsIgnoreCase("")){
			errors.add("last-name-is-mandatory");
			foundError = true;
		}
		if (coyContPerson.getIdentificationDoc() == null || coyContPerson.getIdentificationDoc().equalsIgnoreCase("")){
			errors.add("identification-doc-is-mandatory");
			foundError = true;
		}
		if (coyContPerson.getIdentificationDocNo() == null || coyContPerson.getIdentificationDocNo().equalsIgnoreCase("")){
			errors.add("identification-no-is-mandatory");
			foundError = true;
		}
		if (coyContPerson.getTitle() == null || coyContPerson.getTitle().equalsIgnoreCase("")){
			errors.add("title-is-mandatory");
			foundError = true;
		}
		if (Validator.isEmailAddress(coyContPerson.getEmailAddress())==false){
			
			foundError = true;
			errors.add("email-is-not-valid");
		}
		
		return foundError;
	}
	
	
	public static boolean validateContact_Information(
			Contact_Information contactInfo, List<String> errors) {

		boolean foundError = false;
		
		if (contactInfo.getPhoneMobile() == null || contactInfo.getPhoneMobile().equalsIgnoreCase("")){
			errors.add("mobile-no-mandatory");
			foundError = true;
		}
		if (contactInfo.getEmailAddress() == null || contactInfo.getEmailAddress().equalsIgnoreCase("")){
			errors.add("email-is-mandatory");
			foundError = true;
		}
		if (Validator.isEmailAddress(contactInfo.getEmailAddress())==false){
			errors.add("email-is-not-valid");
			foundError = true;
			
		}
		

		return foundError;
	}
	public static boolean validateApplication_PropertyInformation(
			Property_Information propInfo, List<String> errors) {
		boolean foundError = false;
		
		if (propInfo.getPropertyType() == null || propInfo.getPropertyType().equalsIgnoreCase("")){
			errors.add("property-type-mandatory");
			foundError = true;
		}
		
//		if (propInfo.getBlockNo() == null || propInfo.getBlockNo().equalsIgnoreCase("")){
//			errors.add("block-no-mandatory");
//			foundError = true;
//		}
		if (propInfo.getPlotNo() == null || propInfo.getPlotNo().equalsIgnoreCase("")){
			errors.add("plotno-is-mandatory");
			foundError = true;
		}
		if (propInfo.getArea() == null || propInfo.getArea()==0 ){
			errors.add("area-is-mandatory");
			foundError = true;
		}
		if (propInfo.getState() == null || propInfo.getState().equalsIgnoreCase("")){
			errors.add("state-is-mandatory");
			foundError = true;
		}
		
		if (propInfo.getLandLocation() == null || propInfo.getLandLocation().equalsIgnoreCase("")){
			errors.add("land-location-is-mandatory");
			foundError = true;
		}
		
		if (propInfo.getCity() == null || propInfo.getCity().equalsIgnoreCase("")){
			errors.add("city-is-mandatory");
			foundError = true;
		}
		if (propInfo.getCountry() == null || propInfo.getCountry().equalsIgnoreCase("") ){
			errors.add("country-is-mandatory");
			foundError = true;
		}
		
		if (propInfo.getAllocationMadToYou() == null || propInfo.getAllocationMadToYou().equalsIgnoreCase("") ){
			errors.add("allocation-made-is-mandatory");
		}
		
		if (propInfo.getAssignedToYou() == null || propInfo.getAssignedToYou().equalsIgnoreCase("") ){
			errors.add("assigned-to-you");
		}
		
		return foundError;
	}	
	public static boolean validateApplication_PropertyInformationStateLand(
			Property_Information propInfo, List<String> errors) {
		boolean foundError = false;
		
		
		if("town".equalsIgnoreCase(propInfo.getLocationType())){
			if (propInfo.getLga()== null || propInfo.getLga().equalsIgnoreCase("")){
				errors.add("lga-is-mandatory");
				foundError = true;
			}
			
			if (propInfo.getVillage() == null || propInfo.getVillage().equalsIgnoreCase("")){
				errors.add("village-is-mandatory");
				foundError = true;
			}
			
			if (propInfo.getVillage() == null || propInfo.getVillage().equalsIgnoreCase("")){
				errors.add("city-is-mandatory");
				foundError = true;
			}
		}else{
			if (propInfo.getLandLocation() == null || propInfo.getLandLocation().equalsIgnoreCase("")){
				errors.add("land-location-is-mandatory");
				foundError = true;
			}
		}
	
		
	
		return foundError;
	}	
	
	public static boolean validateApplication_PropertyInformationStateLandHeldPlots(
			List<Held_Plots> heldPlots, List<String> errors) {
		boolean foundError = false;
		
		for (int i = 0; i <heldPlots.size(); i++) {
			Held_Plots held_plotItem = heldPlots.get(i);
			
			if (held_plotItem.getLocation()== null || held_plotItem.getLocation().equalsIgnoreCase("")){
				errors.add("location-is-mandatory");
				foundError = true;
			}
			if (held_plotItem.getArea()== null  || held_plotItem.getArea().equalsIgnoreCase("")){
				errors.add("area-is-mandatory");
				foundError = true;
			}
			//heldPlot.setAcquisitionMode(held_plotItem.getAcquisitionMode());
			//heldPlot.setRegParticulars(held_plotItem.getRegParticulars());
		
			
			
		}
	
		return foundError;
	}	
}
